home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / tracker-4.13.lha / tracker / autoinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  1.3 KB  |  73 lines

  1. /* autoinit.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: autoinit.c,v 4.9 1995/02/08 13:14:56 espie Exp $ 
  6.  * $Log: autoinit.c,v $
  7.  * Revision 4.9  1995/02/08  13:14:56  espie
  8.  * *** empty log message ***
  9.  *
  10.  * Revision 4.9  1995/02/08  13:14:56  espie
  11.  * *** empty log message ***
  12.  *
  13.  * Revision 4.8  1995/02/01  20:41:45  espie
  14.  * *** empty log message ***
  15.  *
  16.  * Revision 4.8  1995/02/01  20:41:45  espie
  17.  * *** empty log message ***
  18.  *
  19.  * Revision 4.7  1995/02/01  16:39:04  espie
  20.  * Includes moved to defs.h
  21.  *
  22.  * Revision 4.7  1995/02/01  16:39:04  espie
  23.  * Includes moved to defs.h
  24.  *
  25.  */
  26.  
  27.  
  28. #include "defs.h"
  29. #include "extern.h"
  30.  
  31. ID("$Id: autoinit.c,v 4.9 1995/02/08 13:14:56 espie Exp $")
  32.  
  33. LOCAL struct clist
  34.     {
  35.     struct clist *next;
  36.     void (*func) P((void));
  37.     } *list = 0;
  38.     
  39.  
  40. void at_end(cleanup)
  41. void (*cleanup) P((void));
  42.     {
  43. #ifdef USE_AT_EXIT
  44.     atexit(cleanup);
  45. #else
  46.     struct clist *new;
  47.     new = (struct clist *)malloc(sizeof(struct clist));
  48.     if (!new)
  49.         {
  50.         (*cleanup)();
  51.         end_all("Allocation problem");
  52.         }
  53.     new->next = list;
  54.     new->func = cleanup;
  55.     list = new;
  56. #endif
  57.     }
  58.     
  59. void end_all(s)
  60. char *s;
  61.     {
  62. #ifndef USE_AT_EXIT
  63.     struct clist *p;
  64. #endif
  65.     if (s)
  66.         notice(s);
  67. #ifndef USE_AT_EXIT
  68.     for (p = list; p; p = p->next)
  69.         (p->func)();            /* don't bother freeing (malloc) */
  70. #endif
  71.     exit(s ? 10 : 0);
  72.     }
  73.